package com.oa.co.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.oa.co.bo.PerformanceBo;
import com.oa.co.pojo.Performance;
import com.oa.co.service.PerformanceService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @date 2023/5/4
 * @desc
 */
@Component
@Scope("prototype")     // 注意 这里要设置成多例模式
public class WebPerformanceListener extends AnalysisEventListener<PerformanceBo> {

    @Autowired
    PerformanceService performanceService;

//    List<PerformanceBo> list = new ArrayList<>();
    @Override
    public void invoke(PerformanceBo data, AnalysisContext context) {
        //每读取一行数据  都会调用这个方法
        //list.add(data);
        System.out.println(data);
        Performance performance = new Performance();
        //student.setId(data.getId());
        //属性拷贝方法
        BeanUtils.copyProperties(data,performance);

        performanceService.performanceAdd(performance);

    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {


        //把集合存入数据库
    }
}
